package com.twu.biblioteca.models.entities;

import com.sun.org.apache.bcel.internal.generic.InstructionComparator;
import com.twu.biblioteca.config.LibaryResourceType;
import org.ietf.jgss.GSSName;

public abstract class LibaryResource {
    private boolean available = true;
    private String name;
    private boolean valid = true;

    public void setName(String name) {
        this.name = name;
    }

    public boolean isAvailable() {
        return available;
    }

    public String getName() {
        return name;
    }

    public void setAvailable(boolean available) {
        this.available = available;
    }

    public LibaryResourceType getLibaryResourceType() {
        String className = getClassName();
        for (LibaryResourceType resourceType : LibaryResourceType.values()) {
            if (resourceType.name().toLowerCase().equals(className.toLowerCase())) {
                return resourceType;
            }
        }
        return null;
    }

    private String getClassName() {
        String[] classNames =  this.getClass().getName().split("\\.");
        return classNames[classNames.length-1];
    }

    public boolean isValid() {
        return valid;
    }

    public void setValid(boolean valid) {
        this.valid = valid;
    }
}
